﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace QLThuVien
{
    class Truyxuatdulieu
    {
        public Truyxuatdulieu()
        {
            KetNoi.setconnect();
        }

        public DataSet getdata(string truyvan)
        {
            try
            {
                DataSet ds = new DataSet(); 
                SqlCommand sqlcommand = new SqlCommand(truyvan, KetNoi.scn);
                SqlDataAdapter sd = new SqlDataAdapter(sqlcommand);
                sd.Fill(ds, "bang");
                
                KetNoi.closeconnect();
                return ds;
            }
            catch { return null; }
        }


        public SqlDataReader lay_reader(string truyvan)
        {
            try
            {
                DataSet ds = new DataSet(); ;
                SqlCommand cmd = new SqlCommand(truyvan, KetNoi.scn);
                SqlDataReader dr = cmd.ExecuteReader();

                return dr;

            }
            catch { return null; }
        }
          
        public int thucthitruyvan(string truyvan)
        {
            try
            {
                SqlCommand cmd =new SqlCommand(truyvan,KetNoi.scn);
                cmd.ExecuteNonQuery();
                SqlDataAdapter ds=new SqlDataAdapter(cmd);
                return 1;
            }
            catch{return 0;}
        }
    }
}
